package code.class1;

/**
 * https://leetcode.cn/problems/fan-zhuan-dan-ci-shun-xu-lcof/
 * <p>
 * 字符串中的单词反转
 */
public class Code11_ReverseMessage {
    public static void main(String[] args) {
        String str = "a good   example";
        String res = reverseMessage(str);
        System.out.println("res = " + res);
    }

    private static String reverseMessage(String message) {
        String[] arr = message.split(" ");
        StringBuilder sb = new StringBuilder();

        for (int i = arr.length - 1; i >= 0; i--) {
            if (!"".equals(arr[i])) {
                sb.append(arr[i]).append(" ");
            }
        }
        return sb.toString().trim();
    }
}
